package cn.tsinghua.comsmacitccntsinghua.tinker;

import android.annotation.TargetApi;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;

import androidx.multidex.MultiDex;

import com.tencent.tinker.anno.DefaultLifeCycle;

import com.tencent.tinker.lib.tinker.Tinker;

import com.tencent.tinker.loader.app.DefaultApplicationLike;
import com.tencent.tinker.loader.shareutil.ShareConstants;

import java.util.ArrayList;
import java.util.List;

import cn.tsinghua.comsmacitccntsinghua.VO.BinVO;
import cn.tsinghua.comsmacitccntsinghua.bean.BaseDataInfo;

/**
 * @Author yjl
 * @create 2021/10/12 19:47
 */

@DefaultLifeCycle(
        application = ".MyApplication",
        loaderClass = "com.tencent.tinker.loader.TinkerLoader",
        flags = ShareConstants.TINKER_ENABLE_ALL,
        loadVerifyFlag = false
)
public class SampleApplicationLike extends DefaultApplicationLike {
    /**原Application的内容**/
    public static SharedPreferences sp;
    public static SharedPreferences.Editor editor;

    public static Application application;

    public SampleApplicationLike(Application application, int tinkerFlags, boolean tinkerLoadVerifyFlag,
                                 long applicationStartElapsedTime, long applicationStartMillisTime, Intent tinkerResultIntent) {
        super(application, tinkerFlags, tinkerLoadVerifyFlag, applicationStartElapsedTime, applicationStartMillisTime, tinkerResultIntent);
    }



    @Override
    public void onCreate() {
        super.onCreate();
        //在这里把之前Application中的初始化搬到这里
        sp = application.getSharedPreferences("TEMPDATA",Context.MODE_PRIVATE);
        editor = sp.edit();
    }

    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
    @Override
    public void onBaseContextAttached(Context base) {
        super.onBaseContextAttached(base);
        MultiDex.install(base);//这里加上分dex

        SampleApplicationLike.application = getApplication();

        TinkerManager.setTinkerApplicationLike(this);
        TinkerManager.setUpgradeRetryEnable(true);
        TinkerManager.installTinker(this);
        Tinker.with(getApplication());
    }


    public static void saveData(String key,String value){
        editor.putString(key,value);
        editor.commit();
    }
    public static void clearData(){
        editor.clear();
        editor.commit();
    }
    public static String  getStrData(String key){
        return sp.getString(key,"");
    }
}